/**
 * 
 */
package __base;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * @author gb
 *
 */
public class Rule {
	/**
	 * Properties
	 */
	private List<String> conclusions;
	private List<String> conditions;
	
	/**
	 * Default constructor
	 */
	public Rule() {
		super();
		this.conclusions = new LinkedList<String>();
		this.conditions = new LinkedList<String>();
	}

	/**
	 * Constructor to use mainly
	 * @param conditions
	 * @param conclusions
	 */
	public Rule(LinkedList<String> conditions, LinkedList<String> conclusions){
		this.conditions = conditions;
		this.conclusions = conclusions;
	}

	public void addCondition(String condition){
		this.conditions.add(condition);
	}
	
	public void addConclusion(String conclusion){
		this.conclusions.add(conclusion);
	}
	/**
	 * @return the conclusions
	 */
	public List<String> getConclusions() {
		return conclusions;
	}

	/**
	 * @return the conditions
	 */
	public List<String> getConditions() {
		return conditions;
	}

	/**
	 * @param conclusions the conclusions to set
	 */
	public void setConclusions(List<String> conclusions) {
		this.conclusions = conclusions;
	}

	/**
	 * @param conditions the conditions to set
	 */
	public void setConditions(List<String> conditions) {
		this.conditions = conditions;
	}

	public String toString() {
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append("IF ");
		ListIterator<String> listIterator = this.conditions.listIterator();
		while (listIterator.hasNext()){
			sBuffer.append((String) listIterator.next()+",");			
		}
		sBuffer.deleteCharAt(sBuffer.length()-1); //Deletes the last comma
		sBuffer.append(" THEN ");
		ListIterator<String> listIterator2 = this.conclusions.listIterator();
		while (listIterator2.hasNext()){
			sBuffer.append((String) listIterator2.next()+",");			
		}
		sBuffer.deleteCharAt(sBuffer.length()-1); //Deletes the last comma
		return sBuffer.toString();
	}
}
